﻿using IdentityServer4;
using IdentityServer4.Models;
using System.Collections.Generic;

namespace OAuth.Server.OAuth
{
    public class Constants
    {
        internal static IEnumerable<Client> Clients => new[]
        {
            new Client
            {
                ClientId = "shay",
                AllowedGrantTypes = new[]
                {
                    GrantType.ResourceOwnerPassword,
                    GrantType.ClientCredentials
                },
                ClientSecrets =
                {
                    new Secret("secret".Sha256())
                },
                RedirectUris = {"http://www.baidu.com"},
                AllowOfflineAccess = true,
                RefreshTokenUsage =  TokenUsage.OneTimeOnly,
                RefreshTokenExpiration = TokenExpiration.Absolute,
                AbsoluteRefreshTokenLifetime = 1800,
                UpdateAccessTokenClaimsOnRefresh = true,
                AccessTokenLifetime = 7200,
                AllowedScopes =
                {
                    "shay_api",
                    IdentityServerConstants.StandardScopes.OfflineAccess,
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile
                }
            },
            new Client
            {
                ClientId = "shay_code",
                ClientName = "i车保应用",
                LogoUri = "http://oss.i-cbao.com/icb.png",
                AllowedGrantTypes = new[]{GrantType.AuthorizationCode},
                ClientSecrets =
                {
                    new Secret("secret".Sha256())
                },
                RedirectUris = {"http://www.baidu.com"},
                AllowOfflineAccess = true,
                AllowAccessTokensViaBrowser = true,
                AccessTokenLifetime = 7200,
                AllowedScopes =
                {
                    "shay_api",
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile
                }
            },
            new Client
            {
                ClientId = "implicit",
                AllowedGrantTypes = GrantTypes.Implicit,
                RedirectUris = {"http://localhost:53690/signin-oidc"},
                PostLogoutRedirectUris = {"http://localhost:53690/signout-callback-oidc"},
                AllowedScopes = new[]
                {
                    "shay_api",
                    IdentityServerConstants.StandardScopes.OpenId,
                    IdentityServerConstants.StandardScopes.Profile
                },
                AccessTokenLifetime = 7200, // one hour
                AllowAccessTokensViaBrowser = true // can return access_token to this client
            }
        };

        internal static IEnumerable<ApiResource> Apis => new[]
        {
            new ApiResource("shay_api","获取店铺信息")
        };

        internal static IEnumerable<IdentityResource> Identities => new IdentityResource[]
        {
            new IdentityResources.OpenId{DisplayName = "获得您的ID"},
            new IdentityResources.Profile{DisplayName = "获得您的昵称、头像、性别"}
        };
    }
}
